import 'package:flutter/cupertino.dart';

typedef SizeReporterCall = Function(double width, double height);

class SizeReporter extends StatefulWidget {
  final Widget child;
  final SizeReporterCall? call;

  // ignore: use_key_in_widget_constructors
  const SizeReporter({required this.child, this.call});

  @override
  _SizeReporterState createState() => _SizeReporterState();
}

class _SizeReporterState extends State<SizeReporter> {
  @override
  Widget build(BuildContext context) {
    WidgetsBinding.instance?.addPostFrameCallback((callback) {
      if (widget.call != null) {
        widget.call!(context.size?.width ?? 0, context.size?.height ?? 0);
      }
    });
    return GestureDetector(
      child: widget.child,
    );
  }
}
